home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / routh < prev    next >
Internet Message Format  |  1995-03-31  |  13KB

  1. From helens!shelby!rutgers!uwm.edu!ux1.cso.uiuc.edu!iuvax!noose.ecn.purdue.edu!en.ecn.purdue.edu!ryoder Mon Jul  2 12:08:13 PDT 1990
  2. Status: RO
  3.  
  4. Article 2050 of comp.sys.handhelds:
  5. Path: helens!shelby!rutgers!uwm.edu!ux1.cso.uiuc.edu!iuvax!noose.ecn.purdue.edu!en.ecn.purdue.edu!ryoder
  6. >From: ryoder@ecn.purdue.edu (Robert W Yoder)
  7. Newsgroups: comp.sys.handhelds
  8. Subject: Routh-Hurwitz
  9. Keywords: Routh-Hurwitz
  10. Message-ID: <1990Jul2.163652.4190@ecn.purdue.edu>
  11. Date: 2 Jul 90 16:36:52 GMT
  12. Organization: Purdue University Engineering Computer Network
  13. Lines: 245
  14.  
  15. The following is the response I received from Paul Dujmich after I sent him a
  16. Routh-Hurwitz program I had written.  I had never posted it because I had not
  17. gotten around to adding the necessary code to cover the special cases.  He
  18. expanded it to cover those cases, so here it is.
  19.  
  20. Robert Yoder
  21. ryoder@ecn.purdue.edu
  22.  
  23. --------------------------------------------------------------------------------
  24. Bob
  25.  
  26. I took the liberty of modifying your basic Routh program for the purpose of
  27. adding special case checking. Most of the special case code is in a separate
  28. subroutine I call "ARYCHK". It was just easier to do it this way.
  29. The new code checks for left-most column zero, as well as zeroes all the
  30. way across a row (premature termination). I believe these two are the
  31. only special cases to worry about. I have tested the new version on my
  32. homework problems, which I had worked out by hand. They included all the
  33. special case conditions mentioned above. The program produced accurate
  34. results for every polynomial that was tried.
  35. One note is in order.
  36. For left-most zero, we use the epsilon method, replacing the 0 with epsilon,
  37. a very small number approaching zero.Then we take the limit of the term,
  38. as epsilon approaches 0. In the program, I use  +/- 1E-50 to represent
  39. epsilon. This works fine, but produces slightly different numbers in the
  40. finished array (compared to the limit method). But, we really don't care
  41. about the actual values anyway, all we care about is the sign changes, and
  42. the program has been correct in every case tested. For zeroes all the way
  43. across a row, I do the accepted method of forming a new Aux polynomial
  44. from the coefficients in the row just above the row of zeroes. Then I take
  45. the derivative of the Aux polynomial, and use the new coefficients to
  46. replace the row of zeroes. This has also worked flawlessly for every thing
  47. that was tried.
  48.  
  49. Please feel free to post this version on net.handhelds if you want. I'm sure
  50. there are other EE/BSET people who would like to have it. Thanks again for
  51. your reply to my posting, and for your original program. It sure was a lot
  52. easier not having to start from scratch. Well anyway, here's the updated
  53. version.
  54.  
  55.  
  56. Thanks Again
  57.  
  58. Paul
  59. pauld@fs1.ece.cmu.edu
  60.  
  61. ============================================================================
  62. %%HP: T(3)A(R)F(.);
  63. @ PROGRAM NAME:  ROUTH
  64. @ DATE:          6-30-90
  65. @ PURPOSE:       Does Routh-Hurwitz Stability Testing
  66. @ ARGUMENTS:     1. An array in level 2 containing coefficients of the
  67. @                   characteristic polynomial from the transfer function.
  68. @                2. The ORDER of the characteristic polynomial in level 1
  69. @ NOTE: This program requires "ARYCHK", a subroutine that checks for special
  70. @       cases, to operate.
  71.  
  72.  
  73. @Routh-Hurwitz  Program
  74. @This program tests the characteristic polynomial of a transfer function
  75. @for stability. The program expects an array as input, which is made up of
  76. @the coefficients of the characteristic polynomial. The array must be in stack
  77. @level 2 when the program is executed. The program also expects the ORDER of
  78. @the characteristic polynomial in level 1.
  79. @The program outputs a Routh-Hurwitz array as it's output.
  80. @The stability of the system being tested can be obtained
  81. @by examining the left-most column of the output array. If all elements in the
  82. @left-most column of the array are of the same sign, the system is STABLE, and
  83. @all of the polynomial roots are in the left-half plane of the complex plane.
  84. @If there are any sign changes within these elements, then the system is
  85. @UNSTABLE, and the polynomial has roots in the RIGHT HALF PLANE of the complex
  86. @plane, or
  87. @it has roots on the IMAGINARY AXIS of the complex plane. The NUMBER of sign
  88. @changes within the left-most array elements give the number of roots in the
  89. @right half plane. The program tests each input array for the following
  90. @SPECIAL CASES, and applies a fix, so that the array may be completed:
  91. @            Special Case 1. Zero in left-most array element
  92. @            Special Case 2. Zeroes all the way across a row
  93.  
  94.  
  95. \-> ord             @load in polynomial ORDER
  96.  
  97. \<< DUP             @make copy of input array on stack
  98.     SIZE            @return dimensions of input array {2 2} on stack
  99.     LIST\->         @dump the array dimensions from list to stack
  100.                     @ 2   (rows)
  101.                     @ 2   (columns)
  102.                     @ 2   (there were 2 elements in the list)
  103.     DROP            @throw away the #elements in list, don't need it
  104.     'cols' STO      @save # columns of input array
  105.     DROP            @drop off # columns from stack
  106.     cols 3 *        @new # of rows = 3* original # columns
  107.     cols            @orig number of columns
  108.     2 \->LIST       @put last 2 elements in a list
  109.     RDM             @redimension input array to size specified by list
  110.     'a' STO         @save the redimensioned array
  111.     3 'r' STO       @start calculating at row 3
  112.     1 CF            @clear flag 1 in case it is set
  113.  
  114. @**************** calculate # of coefficients in orig array  *************
  115.  
  116. ord 1 +             @increment polynomial order to get # coefficients
  117. 'coef' STO          @save it
  118.  
  119. @************** Check row 2 of input array for special cases ***************
  120.  
  121. CLEAR                 @clear stack
  122. 3 'r' STO
  123. ARYCHK                @check row 2 of the input array for special cases
  124.                       @if they exist-fix them.
  125.  
  126. @********************** main DO LOOP ****************************************
  127. 3 'r' STO           @start calculating at row 3
  128.   DO
  129.      1 cols 1 -     @set up FOR loop for 1 less than number of columns
  130.      FOR c
  131.          a          @put array on stack
  132.          r          @put current row on stack
  133.          c          @put current column within current row on stack
  134.          2 \->LIST  @make a list of last 2
  135.  
  136.          @************* array element calculation ************************
  137.          '(a(r-1,1)*a(r-2,c+1)-a(r-2,1)*a(r-1,c+1))/a(r-1,1)'
  138.          EVAL
  139.          PUT        @put the calculated element back into the array
  140.          'a' STO    @save the updated array
  141.      NEXT
  142.      1 'r' STO+     @increment to next row
  143.      ARYCHK         @check for special cases
  144. UNTIL 1 FS?         @run DO loop until flag 1 is set
  145. END
  146. a                   @ put array on stack
  147. r 1 - cols 2 \->LIST
  148. RDM                 @ redimension the array
  149. { a cols r s cnt coef hc pwr}  @list of variables to nuke
  150. PURGE               @nuke them
  151. 1 CF                @clear flag 1
  152. \>>
  153. =============================================================================
  154. %%HP: T(3)A(R)F(.);
  155. @ PROGRAM NAME:  ARYCHK  (subroutine for Routh-Hurwitz Program)
  156. @ DATE:          6-30-90
  157. @ PURPOSE:       checks a row of a Routh-Hurwitz array for special cases
  158. @ARGUMENTS:      Variable 'r' must exist and contain the row of the Routh-
  159.                  @Hurwitz array (+1) to be checked.
  160.  
  161. \<<
  162.      IF 'a(r-1,1)==0'                     @if leftmost element of last row == 0
  163.                THEN
  164.                    IF 'r-1 > coef'        @normal valid array termination
  165.                            THEN 1 SF          @set the flag
  166.  
  167.                           @special case checking
  168.                             ELSE 0 'cnt' STO        @clear cnt
  169.                             1 cols                  @FOR loop goes from 1 to
  170.                                                     @ # columns
  171.                             FOR c
  172.                                 'a(r-1,c)' EVAL     @count # valid array
  173.                                                     @elements in row where 0
  174.                                                     @occurred
  175.                                 0 \=/               @element !=0?
  176.                                 'cnt' STO+          @if yes, then valid
  177.                             NEXT
  178.                             IF 'cnt==0'             @the whole row had 0's
  179.  
  180.                                @premature termination of array (all 0's in row)
  181.                                   THEN
  182.                                      coef r 2 -  -  @calculate first power of
  183.                                                     @S for new polynomial
  184.                                      'pwr' STO      @save it
  185.                                      1 cols         @FOR loop goes from 1 to
  186.                                                     @width of a column
  187.                                      FOR c
  188.                                          'a(r-2,c)'
  189.                                          EVAL       @get term coefficient
  190.                                          "*S^"
  191.                                          +          @add it to string
  192.                                          pwr        @get the exponent
  193.                                          +          @add it to string
  194.                                          "'"
  195.                                          SWAP
  196.                                          +          @make algebraic object
  197.                                                     @ inside a string
  198.                                          OBJ\->     @remove string quotes
  199.                                                     @object is now algebraic
  200.                                          1 'S' STO
  201.                                          'S'        @variable of differentiation
  202.                                          \.d        @take the derivative
  203.                                          EVAL       @evaluate at S = 1
  204.                                          a SWAP     @put array on stack
  205.                                          r 1 - c 2 \->LIST @elem to change
  206.                                          SWAP
  207.                                          PUT        @correct the element
  208.                                          'a' STO    @save updated array
  209.                                          pwr 2 -    @decrement exponent by 2
  210.                                          'pwr' STO  @save new power
  211.                                          IF pwr 0 < @if exponent < 0 then
  212.                                                     @terminate the FOR loop
  213.                                             THEN cols 1 +
  214.                                                  'c' STO
  215.                                          END
  216.                                      NEXT
  217.                                      'S' PURGE      @ done with S for now
  218.  
  219.                               @zero in left-most column only
  220.                                 ELSE 0 'cnt' STO    @clear cnt
  221.                                      1 coef         @FOR loop goes from 1 to
  222.                                                     @ # of coefficients
  223.                                      FOR c
  224.                                           'a(c,1)'   @count the number of left
  225.                                           EVAL       @most elements that are
  226.                                           0 <        @negative
  227.                                           'cnt' STO+ @cnt has total
  228.                                      NEXT
  229.                                      coef 2 /        @find half #coefficients
  230.                                      IP              @only the integer part
  231.                                      'hc' STO        @save it in hc
  232.                                      IF 'cnt > hc'   @more than 1/2 the
  233.                                                      @coefficients are negative
  234.                                        THEN  a       @get array
  235.                                              r 1 - 1 2
  236.                                              \->LIST    @array element to change
  237.                                              -1.E-50    @make it neg
  238.                                              PUT        @put in array
  239.                                              'a' STO    @save changed array
  240.                                        ELSE  a          @get array
  241.                                              r 1 - 1 2  @select element
  242.                                              \->LIST
  243.                                              1.E-50   @make it pos
  244.                                              PUT      @put in array
  245.                                              'a' STO  @save changed array
  246.                                      END
  247.  
  248.                             END
  249.                    END
  250.  
  251.      END
  252.    \>>
  253. ==============================================================================
  254.  
  255. -- 
  256. --------------------------------------------------------------------------------
  257. Robert Yoder
  258.  
  259. Internet: ryoder@ecn.purdue.edu
  260.  
  261.  
  262.